package com.proyecto.track.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

import com.proyecto.track.bo.UserType;
@Transactional
public class UserTypeDAOImp implements UserTypeDAO{

private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@Override
	public Long createUserType(UserType userType) {
		sessionFactory.getCurrentSession().save(userType);
		return userType.getId();
	}

	@Override
	public Long deleteUserType(UserType userType) {
		Long id = userType.getId();
		sessionFactory.getCurrentSession().delete(userType);
		return id;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UserType> searchUserType() {
		return  sessionFactory.getCurrentSession().createQuery("from UserType").list();
	}

	@Override
	public UserType searchUserType(Long id) {
		return (UserType) sessionFactory.getCurrentSession().get(UserType.class, id);
	}

}
